package com.ydd.controller.admin;

import com.ydd.dto.LoginDTO;
import com.ydd.result.Result;
import com.ydd.service.SysConfigService;
import com.ydd.service.IndexService;
import com.ydd.vo.BaseInfoVO;
import com.ydd.vo.JWtToken;
import com.ydd.vo.ProfileVO;
import com.ydd.vo.SystemConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

@RestController("adminIndexController")
@Api(tags = "索引相关接口")
@RequestMapping("/index")
@Slf4j
public class IndexController {

    @Autowired
    IndexService indexService;

    @Autowired
    SysConfigService sysConfigService;


    /**
     * 登录接口
     *
     * @param loginDTO
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("登录接口")
    public Result<JWtToken> login(@RequestBody LoginDTO loginDTO) {
        log.info("用户登录:{},{}", loginDTO.getLoginName(), loginDTO.getPassword());
        JWtToken token = indexService.login(loginDTO);

        return Result.success(token);
    }


    /**
     * 获取系统配置
     *
     * @return
     */
    @GetMapping("/getConfig")
    @ApiOperation("获取系统配置")
    public Result<SystemConfigVO> getConfig() {
        log.info("获取系统配置");
        SystemConfigVO systemConfigVO = sysConfigService.getIndexConfig();

        return Result.success(systemConfigVO);
    }

    /**
     * 获取主页统计信息
     *
     * @return
     */
    @GetMapping("/baseInfo")
    @ApiOperation("主页统计信息接口")
    public Result<BaseInfoVO> baseInfo() {
        log.info("获取主页统计信息");
        BaseInfoVO baseInfoVO = indexService.baseInfo();
        return Result.success(baseInfoVO);
    }

    /**
     * 获取用户资料
     *
     * @return
     */
    @PostMapping("/profile")
    @ApiOperation("获取用户资料")
    public Result proFile() {
        log.info("获取用户资料");
        ProfileVO profileVO = indexService.profile();
        return Result.success(profileVO);
    }
}
